(function(){
	
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	var currentPage = 1;
	var pageSize = 10;
	var totalSize;
	var now = 0;
	var dataCache = [];
	$(function(){
		var username = $("#user-name",parent.parent.document).attr("title");
		var usercode = $("#user-name",parent.parent.document).attr("code");
		var userkey = $("#user-name",parent.parent.document).attr("key");
		var usertype = $("#user-name",parent.parent.document).attr("usertype");
		keyCheck(usercode,usertype,userkey,function(){
			initSmPages();
			window.onresize = function () {
				initSmPages();
			};
			pagebtns();
			initRule(currentPage,pageSize);
			 
		});
	});
	function initRule(currentpage,pagesize){
		var userKey = $("#user-name",parent.parent.document).attr("key");		
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var name = encodeURI($("#rule-name").val());
		var data = {
				cmd:"queryAttendanceRegular",
				model:"attendance",
				userKey:userKey,
				data:{
					currentpage:currentpage,
					pagesize:pagesize,
					schoolcode:schoolcode,
					name:name,
				},
				remark:"",
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			var content = "";
			var pagecontent = "<div class=\"pages-btn-next\">&gt;&gt;</div>";
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data.data;
				var total = res.data.total;
				totalSize = Math.ceil(total/pagesize);
				if(totalSize <= 5 && totalSize >0){
					for(var i = totalSize-1 ; i >= 0; i--){
						if(i == currentpage-1){
							pagecontent += "<div class=\"pages-btn page-btn-select\">"+(i + 1)+"</div>"; 
						}else{
							pagecontent += "<div class=\"pages-btn\">"+(i + 1)+"</div>"; 
						}
					}
				}else if(totalSize == 0){
					pagecontent += "<div class=\"pages-btn\">1</div>";
				}else if(totalSize > 5){
					var lastp = (now*5)+5;
					if(lastp > totalSize){
						lastp = totalSize;
					}
					for(var i = lastp-1 ; i >= (now*5); i--){
						if(i == currentpage-1){
							pagecontent += "<div class=\"pages-btn page-btn-select\">"+(i + 1)+"</div>"; 
						}else{
							pagecontent += "<div class=\"pages-btn\">"+(i + 1)+"</div>"; 
						}
					}
				}
				pagecontent += "<div class=\"pages-btn-last\">&lt;&lt;</div>";
				$("#student-page").empty();
				$("#student-page").append(pagecontent);
				
				$(".pages-btn").unbind("click");
				$(".pages-btn").click(function(){
					$(".pages-btn").removeClass("page-btn-select");
					$(this).addClass("page-btn-select");
					currentPage = parseInt($(this).text());
					initRule(currentPage,pageSize);
				});
				
				$(".pages-btn-last").unbind("click");
				$(".pages-btn-last").click(function(){
					if(totalSize <= 5 && totalSize >0){
						return false;
					}else if(totalSize == 0){
						return false;
					}else if(totalSize > 5){
						if(now > 0){
							now --;
							initRule((now*5+1),pageSize);
						}else{
							return false;
						}
					}
				});
				
				$(".pages-btn-next").unbind("click");
				$(".pages-btn-next").click(function(){
					if(totalSize <= 5 && totalSize >0){
						return false;
					}else if(totalSize == 0){
						return false;
					}else if(totalSize > 5){
						if(totalSize%5 == 0){
							if((now+1) < totalSize/5){
								now ++;
								initRule((now*5+1),pageSize);
							}else{
								return false;
							}
						}else{
							if((now+1) <= (totalSize-totalSize%5)/5){
								now ++;
								initRule((now*5+1),pageSize);
							}else{
								return false;
							}
						}
						
					}
				});
				
				if(data.length > 0){
					dataCache = [];
					for(var i = 0; i < data.length; i++){
						var id = data[i].id;
						for(var key in data[i]){
							if(data[i][key] == null || data[i][key] == "null" || data[i][key] == undefined){
								data[i][key] = "";
							}
						}
						var Name = data[i].name;
						content += "<div class=\"table-trs\">" +
							"<div class=\"tables-left\" style='margin-left:15px;'>" +
								"<div class=\"table-name\" title='"+Name+"'>"+substr(Name,6)+"</div>" +
								"<div class=\"table-code\" title='"+data[i].describe+"'>"+substr(data[i].describe,8)+"</div>" +
							"</div>"  +
							"<div class=\"tables-right\">" +
								"<div class=\"table-address\">"+'创建于：'+getFormatDateByLong(parseInt(data[i].time)*1000,"yyyy-MM-dd hh:mm")+"</div>" +
								"<div class=\"table-oprate\">" +
									"<div class=\"table-detail\" dataindex = \""+i+"\" rulecode=\""+data[i].code+"\" title=\"详情\" classname=\""+Name+"\"></div>" +
									"<div class=\"table-edit\" dataindex = \""+i+"\" rulecode=\""+data[i].code+"\" title=\"编辑\"></div>" +
									"<div class=\"table-delete\" dataindex = \""+i+"\" rulecode=\""+data[i].code+"\"title=\"删除\"></div>" +
								"</div>" +
							"</div>" +
						"</div>";
						dataCache.push(data[i]);
					}
					$("#rule-data-show").empty();
					$("#rule-data-show").append(content);
					
					$(".table-trs").unbind("hover");
					$(".table-trs").hover(function(){
						$(this).find(".table-oprate").show();
					},function(){
						$(".table-oprate").hide();
					});
					
					$(".table-detail").unbind("click");
					$(".table-detail").click(function(){
						var index = parseInt($(this).attr("dataindex"));
						$("#rule-form-show").show();
						$("#right-tables").hide();
						$("#rule-form-show").contents().find("textarea").attr("disabled","disabled");
						$("#rule-form-show").contents().find("textarea").css("background-color","#E5E5E5");
						$("#rule-form-show").contents().find("input").attr("disabled","disabled");
						$("#rule-form-show").contents().find("input").css("background-color","#E5E5E5");
						$("#rule-form-show").contents().find("select").attr("disabled","disabled");
						$("#rule-form-show").contents().find("select").css("background-color","#E5E5E5");
						$("#rule-form-show").contents().find("#back-to-table").unbind("click");
						$("#rule-form-show").contents().find("#back-to-table").click(function(){
							$("#rule-form-show").hide();
							$("#right-tables").show();
						});
						showData(dataCache[index],"detail");
					});
					
					$(".table-edit").unbind("click");
					$(".table-edit").click(function(){
						var index = parseInt($(this).attr("dataindex"));
						$("#rule-form-show").show();
						$("#right-tables").hide();
						$("#rule-form-show").contents().find("textarea").removeAttr("disabled");
						$("#rule-form-show").contents().find("textarea").css("background-color","#fff");
						$("#rule-form-show").contents().find("input").removeAttr("disabled");
						$("#rule-form-show").contents().find("input").css("background-color","#fff");
						$("#rule-form-show").contents().find("select").removeAttr("disabled");
						$("#rule-form-show").contents().find("select").css("background-color","#fff");
						$("#rule-form-show").contents().find("#back-to-table").unbind("click");
						$("#rule-form-show").contents().find("#back-to-table").click(function(){
							$("#rule-form-show").hide();
							$("#right-tables").show();
						});
						showData(dataCache[index],"edit");
						$("#rule-form-show").contents().find("#save-btns").unbind("click");
						$("#rule-form-show").contents().find("#save-btns").click(function(){
							if(checkSave()){
								if(check2()){
									updateRule(dataCache[index].id);
								}
							}
							
						});
						checkParames();
					});
					
					$(".table-delete").unbind("click");
					$(".table-delete").click(function(){
						var index = parseInt($(this).attr("dataindex"));
						deleteBox("确定要删除吗？",function(){
							deleteRule(dataCache[index].id);
						});
					});
				}else{
					content += "<div class=\"table-trs\">" +
									"<div class=\"no-data-show\">没有查到相关结果！</div>" +
								"</div>";
					$("#rule-data-show").empty();
					$("#rule-data-show").append(content);
				}
			}else{
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#rule-data-show").empty();
				$("#rule-data-show").append(content);
			}
		},null,null);	
	}
	function updateRule(id){
		var Id = id;
		var sendcode = $("#user-name",parent.parent.document).attr("code");
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var describe = encodeURI($("#rule-form-show").contents().find("#rule-describe").val());
		var name = encodeURI($("#rule-form-show").contents().find("#rule-name").val());
		var time = strToDate($("#rule-form-show").contents().find("#rule-time").val() + ":00")/1000;
		var morninginschool1 =  ($("#rule-form-show").contents().find("#rule-morninginschool1").val());
		var morningoutschool1 =  ($("#rule-form-show").contents().find("#rule-morningoutschool1").val());
		var morningabsence1 =  ($("#rule-form-show").contents().find("#rule-morningabsence1").val());
		var afternooninschool1 =  ($("#rule-form-show").contents().find("#rule-afternooninschool1").val());
		var afternoonoutschool1 =  ($("#rule-form-show").contents().find("#rule-afternoonoutschool1").val());
		var afternoonabsence1 =  ($("#rule-form-show").contents().find("#rule-afternoonabsence1").val());
		var nightinschool1 =  ($("#rule-form-show").contents().find("#rule-nightinschool1").val());
		var nightoutschool1 =  ($("#rule-form-show").contents().find("#rule-nightoutschool1").val());
		var nightabsence1 =  ($("#rule-form-show").contents().find("#rule-nightabsence1").val());
		var morninginschool2 =  ($("#rule-form-show").contents().find("#rule-morninginschool2").val());
		var morningoutschool2 =  ($("#rule-form-show").contents().find("#rule-morningoutschool2").val());
		var morningabsence2 =  ($("#rule-form-show").contents().find("#rule-morningabsence2").val());
		var afternooninschool2 =  ($("#rule-form-show").contents().find("#rule-afternooninschool2").val());
		var afternoonoutschool2 =  ($("#rule-form-show").contents().find("#rule-afternoonoutschool2").val());
		var afternoonabsence2 =  ($("#rule-form-show").contents().find("#rule-afternoonabsence2").val());
		var nightinschool2 =  ($("#rule-form-show").contents().find("#rule-nightinschool2").val());
		var nightoutschool2 =  ($("#rule-form-show").contents().find("#rule-nightoutschool2").val());
		var nightabsence2 =  ($("#rule-form-show").contents().find("#rule-nightabsence2").val());
		var morninginschool3 =  ($("#rule-form-show").contents().find("#rule-morninginschool3").val());
		var morningoutschool3 =  ($("#rule-form-show").contents().find("#rule-morningoutschool3").val());
		var morningabsence3 =  ($("#rule-form-show").contents().find("#rule-morningabsence3").val());
		var afternooninschool3 =  ($("#rule-form-show").contents().find("#rule-afternooninschool3").val());
		var afternoonoutschool3 =  ($("#rule-form-show").contents().find("#rule-afternoonoutschool3").val());
		var afternoonabsence3 =  ($("#rule-form-show").contents().find("#rule-afternoonabsence3").val());
		var nightinschool3 =  ($("#rule-form-show").contents().find("#rule-nightinschool3").val());
		var nightoutschool3 =  ($("#rule-form-show").contents().find("#rule-nightoutschool3").val());
		var nightabsence3 =  ($("#rule-form-show").contents().find("#rule-nightabsence3").val());
		var morninginschool4 =  ($("#rule-form-show").contents().find("#rule-morninginschool4").val());
		var morningoutschool4 =  ($("#rule-form-show").contents().find("#rule-morningoutschool4").val());
		var morningabsence4 =  ($("#rule-form-show").contents().find("#rule-morningabsence4").val());
		var afternooninschool4 =  ($("#rule-form-show").contents().find("#rule-afternooninschool4").val());
		var afternoonoutschool4 =  ($("#rule-form-show").contents().find("#rule-afternoonoutschool4").val());
		var afternoonabsence4 =  ($("#rule-form-show").contents().find("#rule-afternoonabsence4").val());
		var nightinschool4 =  ($("#rule-form-show").contents().find("#rule-nightinschool4").val());
		var nightoutschool4 =  ($("#rule-form-show").contents().find("#rule-nightoutschool4").val());
		var nightabsence4 =  ($("#rule-form-show").contents().find("#rule-nightabsence4").val());
		var morninginschool5 =  ($("#rule-form-show").contents().find("#rule-morninginschool5").val());
		var morningoutschool5 =  ($("#rule-form-show").contents().find("#rule-morningoutschool5").val());
		var morningabsence5 =  ($("#rule-form-show").contents().find("#rule-morningabsence5").val());
		var afternooninschool5 =  ($("#rule-form-show").contents().find("#rule-afternooninschool5").val());
		var afternoonoutschool5 =  ($("#rule-form-show").contents().find("#rule-afternoonoutschool5").val());
		var afternoonabsence5 =  ($("#rule-form-show").contents().find("#rule-afternoonabsence5").val());
		var nightinschool5 =  ($("#rule-form-show").contents().find("#rule-nightinschool5").val());
		var nightoutschool5 =  ($("#rule-form-show").contents().find("#rule-nightoutschool5").val());
		var nightabsence5 =  ($("#rule-form-show").contents().find("#rule-nightabsence5").val());
		var morninginschool6 =  ($("#rule-form-show").contents().find("#rule-morninginschool6").val());
		var morningoutschool6 =  ($("#rule-form-show").contents().find("#rule-morningoutschool6").val());
		var morningabsence6 =  ($("#rule-form-show").contents().find("#rule-morningabsence6").val());
		var afternooninschool6 =  ($("#rule-form-show").contents().find("#rule-afternooninschool6").val());
		var afternoonoutschool6 =  ($("#rule-form-show").contents().find("#rule-afternoonoutschool6").val());
		var afternoonabsence6 =  ($("#rule-form-show").contents().find("#rule-afternoonabsence6").val());
		var nightinschool6 =  ($("#rule-form-show").contents().find("#rule-nightinschool6").val());
		var nightoutschool6 =  ($("#rule-form-show").contents().find("#rule-nightoutschool6").val());
		var nightabsence6 =  ($("#rule-form-show").contents().find("#rule-nightabsence6").val());
		var morninginschool7 =  ($("#rule-form-show").contents().find("#rule-morninginschool7").val());
		var morningoutschool7 =  ($("#rule-form-show").contents().find("#rule-morningoutschool7").val());
		var morningabsence7 =  ($("#rule-form-show").contents().find("#rule-morningabsence7").val());
		var afternooninschool7 =  ($("#rule-form-show").contents().find("#rule-afternooninschool7").val());
		var afternoonoutschool7 =  ($("#rule-form-show").contents().find("#rule-afternoonoutschool7").val());
		var afternoonabsence7 =  ($("#rule-form-show").contents().find("#rule-afternoonabsence7").val());
		var nightinschool7 =  ($("#rule-form-show").contents().find("#rule-nightinschool7").val());
		var nightoutschool7 =  ($("#rule-form-show").contents().find("#rule-nightoutschool7").val());
		var nightabsence7 =  ($("#rule-form-show").contents().find("#rule-nightabsence7").val());
		var obj = {};
		obj.id = id;
		obj.sendcode = sendcode;
		obj.userkey = userKey;
		obj.schoolcode = schoolcode;
		obj.describe = describe;
		obj.name = name;
		obj.time = time;
		obj.morninginschool1 = morninginschool1;
		obj.morningoutschool1 = morningoutschool1;
		obj.morningabsence1 = morningabsence1;
		obj.afternooninschool1 = afternooninschool1;
		obj.afternoonoutschool1 = afternoonoutschool1;
		obj.afternoonabsence1 = afternoonabsence1;
		obj.nightinschool1 = nightinschool1;
		obj.nightoutschool1 = nightoutschool1;
		obj.nightabsence1 = nightabsence1;
		obj.morninginschool2 = morninginschool2;
		obj.morningoutschool2 = morningoutschool2;
		obj.morningabsence2 = morningabsence2;
		obj.afternooninschool2 = afternooninschool2;
		obj.afternoonoutschool2 = afternoonoutschool2;
		obj.afternoonabsence2 = afternoonabsence2;
		obj.nightinschool2 = nightinschool2;
		obj.nightoutschool2 = nightoutschool2;
		obj.nightabsence2 = nightabsence2;
		obj.morninginschool3 = morninginschool3;
		obj.morningoutschool3 = morningoutschool3;
		obj.morningabsence3 = morningabsence3;
		obj.afternooninschool3 = afternooninschool3;
		obj.afternoonoutschool3 = afternoonoutschool3;
		obj.afternoonabsence3 = afternoonabsence3;
		obj.nightinschool3 = nightinschool3;
		obj.nightoutschool3 = nightoutschool3;
		obj.nightabsence3 = nightabsence3;
		obj.morninginschool4 = morninginschool4;
		obj.morningoutschool4 = morningoutschool4;
		obj.morningabsence4 = morningabsence4;
		obj.afternooninschool4 = afternooninschool4;
		obj.afternoonoutschool4 = afternoonoutschool4;
		obj.afternoonabsence4 = afternoonabsence4;
		obj.nightinschool4 = nightinschool4;
		obj.nightoutschool4 = nightoutschool4;
		obj.nightabsence4 = nightabsence4;
		obj.morninginschool5 = morninginschool5;
		obj.morningoutschool5 = morningoutschool5;
		obj.morningabsence5 = morningabsence5;
		obj.afternooninschool5 = afternooninschool5;
		obj.afternoonoutschool5 = afternoonoutschool5;
		obj.afternoonabsence5 = afternoonabsence5;
		obj.nightinschool5 = nightinschool5;
		obj.nightoutschool5 = nightoutschool5;
		obj.nightabsence5 = nightabsence5;
		obj.morninginschool6 = morninginschool6;
		obj.morningoutschool6 = morningoutschool6;
		obj.morningabsence6 = morningabsence6;
		obj.afternooninschool6 = afternooninschool6;
		obj.afternoonoutschool6 = afternoonoutschool6;
		obj.afternoonabsence6 = afternoonabsence6;
		obj.nightinschool6 = nightinschool6;
		obj.nightoutschool6 = nightoutschool6;
		obj.nightabsence6 = nightabsence6;
		obj.morninginschool7 = morninginschool7;
		obj.morningoutschool7 = morningoutschool7;
		obj.morningabsence7 = morningabsence7;
		obj.afternooninschool7 = afternooninschool7;
		obj.afternoonoutschool7 = afternoonoutschool7;
		obj.afternoonabsence7 = afternoonabsence7;
		obj.nightinschool7 = nightinschool7;
		obj.nightoutschool7 = nightoutschool7;
		obj.nightabsence7 = nightabsence7;
		obj.remark="";
		var data = {
				cmd:"updateAttendanceRegular",
				model:"attendance",
				userKey:userKey,
				schoolcode:schoolcode,
				id:Id,
				data:obj,
				remark:"",						
		};
		processBegin("正在保存中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("编辑考勤规则信息成功");
				initRule(currentPage,pageSize);	
			}else{
				processError("编辑考勤规则信息失败");
			}
		},null,null);
	}
	
	function getFormData(){
		new setTRule(null,null,null,null,null,null,null,null,
				null,null,null,null,null,null,null,null,null,null,
				null,null,null,null,null,null,null,null,null,null,
				null,null,null,null,null,null,null,null,null,null,
				null,null,null,null,null,null,null,null,null,null,
				null,null,null,null,null,null,null,null,null,null,
				null,null,null,null,null,null,null,null,null,null,null);
		var trule = getTRule();
		var obj = {};

		for(var key in trule){
			if($("#rule-"+key)[0]){
				if($("#rule-"+key)[0].tagName.toLocaleLowerCase() == "input"){
						
						if(key=="time"){
							obj[key] = strToDate($("#rule-"+key).val() + ":00")/1000;
						}else if(key=="name"){
							obj[key] = encodeURI($("#rule-"+key).val());
						}else if(key=="describe"){
							obj[key] = encodeURI($("#rule-"+key).val());
						}else{
							obj[key] = $("#rule-"+key).val();
						}
					
				}else{
					obj[key] = encodeURI($("#rule-"+key).val());
				}
			}
		}
		var schoolcode=encodeURI($("#user-name",parent.parent.document).attr("schoolcode"));
		obj.schoolcode=schoolcode;
		var userKey = $("#user-name",parent.parent.document).attr("key");
		obj.userkey = userKey;
		var sendcode = $("#user-name",parent.parent.document).attr("code");
		obj.sendcode = sendcode;
		new setTRule(obj.name,obj.time,obj.userkey,obj.schoolcode,obj.describe,
				obj.morninginschool1,obj.morningoutschool1,obj.morningabsence1,obj.afternooninschool1,
				obj.afternoonoutschool1,obj.afternoonabsence1,obj.nightinschool1,obj.nightoutschool1,
				obj.nightabsence1,
				obj.morninginschool2,obj.morningoutschool2,obj.morningabsence2,obj.afternooninschool2,
				obj.afternoonoutschool2,obj.afternoonabsence2,obj.nightinschool2,obj.nightoutschool2,
				obj.nightabsence2,
				obj.morninginschool3,obj.morningoutschool3,obj.morningabsence3,obj.afternooninschool3,
				obj.afternoonoutschool3,obj.afternoonabsence3,obj.nightinschool3,obj.nightoutschool3,
				obj.nightabsence3,
				obj.morninginschool4,obj.morningoutschool4,obj.morningabsence4,obj.afternooninschool4,
				obj.afternoonoutschool4,obj.afternoonabsence4,obj.nightinschool4,obj.nightoutschool4,
				obj.nightabsence4,
				obj.morninginschool5,obj.morningoutschool5,obj.morningabsence5,obj.afternooninschool5,
				obj.afternoonoutschool5,obj.afternoonabsence5,obj.nightinschool5,obj.nightoutschool5,
				obj.nightabsence5,
				obj.morninginschool6,obj.morningoutschool6,obj.morningabsence6,obj.afternooninschool6,
				obj.afternoonoutschool6,obj.afternoonabsence6,obj.nightinschool6,obj.nightoutschool6,
				obj.nightabsence6,
				obj.morninginschool7,obj.morningoutschool7,obj.morningabsence7,obj.afternooninschool7,
				obj.afternoonoutschool7,obj.afternoonabsence7,obj.nightinschool7,obj.nightoutschool7,
				obj.nightabsence7,
				obj.remark);
		return getTRule();	
	}
	
	function deleteRule(id){
		var Id = id;
		var trule = getFormData();
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var obj = {};
		obj.id = id;
		for(var key in trule){
				obj[key] = trule[key];
		}
		
		var data = {
				cmd:"deleteAttendanceRegular",
				model:"attendance",
				schoolcode:schoolcode,
				userKey:userKey,
				data:obj,
				remark:"",						
		};
		processBegin("正在删除中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("删除成功");
				closeDialog(function(){initRule(1,pageSize);});					
			}else{
				processError("删除失败");
			}
		},null,null);
	}
	function substr(str,len){
		if(str != undefined){
			if(str.length > len){
				str = str.substring(0,len-2)+"...";
				return str;
			}else{
				return str;
			}
		}else{
			return "";
		}
	}
	function showData(data,type){
		if(type == "detail"){
			$("#rule-form-show").contents().find("#save-btns-content").hide();
		}else if(type == "edit"){
			$("#rule-form-show").contents().find("#save-btns-content").show();
		}
		for(var key in data){
			if($("#rule-form-show").contents().find("#rule-" + key)[0]){
				if($("#rule-form-show").contents().find("#rule-" + key)[0].tagName.toLocaleLowerCase() == "input"){
					var time = "";
					if(key=="time"){
						time = getFormatDateByLong(parseInt(data[key])*1000,"yyyy-MM-dd hh:mm");
						$("#rule-form-show").contents().find("#rule-" + key).val(time);
					}else{
						$("#rule-form-show").contents().find("#rule-"+key).val(data[key]);
					}
					
				}else{
					$("#rule-form-show").contents().find("#rule-"+key).val(data[key]);
				}
			}
		}
	}
	
	function check2(){
		var flg = false;
		var checkFails = $("#rule-form-show").contents().find(".check-fail");
		for(var i = 0; i < checkFails.length; i++){
			if(checkFails[i].innerHTML != ""){
				flg = false;
				break;
			}else{
				flg = true;
			}
		}
		return flg;
	}
	
	function checkSave(){
		var flag = false;
		var parame = ["name","describe","time",
		              "morninginschool1","morningoutschool1","morningabsence1","afternooninschool1","afternoonoutschool1","afternoonabsence1",
		              "morninginschool2","morningoutschool2","morningabsence2","afternooninschool2","afternoonoutschool2","afternoonabsence2",
		              "morninginschool3","morningoutschool3","morningabsence3","afternooninschool3","afternoonoutschool3","afternoonabsence3",
		              "morninginschool4","morningoutschool4","morningabsence4","afternooninschool4","afternoonoutschool4","afternoonabsence4",
		              "morninginschool5","morningoutschool5","morningabsence5","afternooninschool5","afternoonoutschool5","afternoonabsence5",
		              ];
		for(var i = 0; i < parame.length; i++){
			if($("#rule-form-show").contents().find("#rule-" + parame[i]).val() == ""){
				$("#rule-form-show").contents().find("#rule-" + parame[i]).focus();
				$("#rule-form-show").contents().find("#rule-" + parame[i] + "-ex").text("不能为空！");
				return false;
			}else{
				flag = true;
			}
		}
		return flag;
	}
	function checkParames(){
		var parame = ["name","describe","time",
		              "morninginschool1","morningoutschool1","morningabsence1","afternooninschool1","afternoonoutschool1","afternoonabsence1",
		              "morninginschool2","morningoutschool2","morningabsence2","afternooninschool2","afternoonoutschool2","afternoonabsence2",
		              "morninginschool3","morningoutschool3","morningabsence3","afternooninschool3","afternoonoutschool3","afternoonabsence3",
		              "morninginschool4","morningoutschool4","morningabsence4","afternooninschool4","afternoonoutschool4","afternoonabsence4",
		              "morninginschool5","morningoutschool5","morningabsence5","afternooninschool5","afternoonoutschool5","afternoonabsence5",
		              ];
		for(var i = 0; i < parame.length; i++){
			check1("rule-"+parame[i],isNull,"null","rule-form-show");
		}
	}
	function pagebtns(){
		$("#rule-search-btn").click(function(){
			now = 0;
			initRule(1,pageSize);
		});
	}
	function initSmPages(){
		var rcH = $(".body-right",parent.document).height() - $(".right-title").height()-3;
		$(".right-content").height(rcH);
		
		var cdsH = $(".right-content").height() - $(".content-title").height() - 40;
		$(".content-data-show").height(cdsH);
	}
})();